/**
 * 事项管理 - 已通过事项
 * 版本号： v1.0.0
 */
$(function () {


    $("#myFinish_List").datagrid({
        title: "已通过采购事项",
        fitColumns: true,
        fit:true,
        method: "POST",
        rownumbers: true,
        singleSelect:true,
        pagination: true,
        striped:true,
        pageSize:10,
        pageList:[10,30,50,100],
        url: CONTEXT_PATH + '/purchase/myFinishList.do',
        idField: 'purId',
        columns: [
            [
                {field: 'prName', title: '项目名称', width: 160, fixed: true},
                {field: 'coName', title: '合同名称', width: 160, fixed: true},
                {field: 'coNumber', title: '合同编号', width: 140, fixed: true},
                {field: 'purCode', title: '采购单号', width: 180, fixed: true},
                {field: 'purType', title: '请购类型', width: 70, fixed: true, align:'center',
                    formatter: function (val) {
                        if (val == 1) return "<span style='color: green; font-weight: bold'>合同内</span>";
                        if (val == 2) return "<span style='color: red; font-weight: bold'>合同外</span>";
                    }},
                /*{field: 'createPerson', title: '请购人', width: 90, fixed: true, align:'center'},*/
                {field: 'purPerson', title: '请购人', width: 90, fixed: true, align:'center'},
                {field: 'checkState', title: '请购状态', width: 70, fixed: true, align:'center',
                    formatter: function (val) {
                        if (val == "2") return "<span style='font-weight: bold; color: green'>已通过</span>";
                }},
                {field: 'purDate', title: '申请时间', width: 135}
            ]
        ],
        onDblClickRow : function(){
            myFinish_view();
        },
        onLoadSuccess:function(data){
            if(data.rows.length > 0){
                $("#myFinish_List").datagrid("selectRow", 0);
            }
        }
    });





    //定义可操作按钮
    $("#myFinish_Menu").dialog({
        title: '',
        width: 'auto',
        height: 35,
        closed: false,
        cache: false,
        inline: true,
        modal: false,
        border: false,
        toolbar: createToolbar()
    });

});


/**
 * 创建toolbar按钮组
 * @returns {Array}
 */
function createToolbar() {
    var toolbar = [];
    var falg = false;
    for (var j = 0; j < btnOptions.length; j++) {
        if (false != btnOptions[j].value) {
            falg = true;
            break;
        }
    }
    if (!falg) {
        //不存在按钮
        toolbar.push({});
    } else {
        //存在按钮
        for (var i = 0; i < btnOptions.length; i++) {
            if (false != btnOptions[i].value) {
                //查看按钮
                if ("viewBtn" == btnOptions[i].key) {
                    toolbar.push({
                        id:btnOptions[i].value.meId,
                        text:btnOptions[i].value.name,
                        iconCls:btnOptions[i].value.iconCls,
                        handler: function () {
                            myFinish_view();
                        }
                    });
                }
            }
        }
    }
    return toolbar;
}

/**
 * 查看
 */
function myFinish_view(){
    var row = $("#myFinish_List").datagrid("getSelected");
    if (null == row) {
        $.messager.show({title: '操作提示', msg: "请选择查看采购申请!", timeout: 3000, showType: "slide"});
        return;
    }
    var purId = row.purId;
    var width = window.parent.window.document.body.offsetWidth;
    var height = window.parent.window.document.body.offsetHeight;
    var url = CONTEXT_PATH + "/purchase/toView.do?purId=" + purId;
    var option = {
        title : "采购任务查看",
        iconCls : "icon-edit",
        width : width,
        height : height,
        closable : true,
        style : {"display" : "block"},
        closed : true,
        minimizable: false,
        maximizable: false,
        collapsible: false,
        content : "<iframe scrolling = 'yes' frameborder = '0'  src='" + url + "' style='width:100%;height:100%'></iframe>"
    }
    window.parent.openTaskWindow(option);

}

